* Author: Gregory Smith
* Date: December 3, 2018 
* Job: Bivariate Probit Robustness Checks: Uses Ongoing Operations as the Primary DV and Replaces NAs in the Peace Year Vecetors with 0s

clear
set more off
*\ set working directory
cd "~/Dropbox/covert_ops_paper/2019-smith-io-secret-but-constrained-replication-files/data/"

*\ open file 
 use smith_2019_secret_but_constrained_dta.dta

 
* Adds Variable Labels (to be used in the Latex output) 

label variable orourke_covert_intervention   "O'Rourke Covert Operation" 
label variable us_covert_operation   "Pooled Covert Operation" 
label variable major_ongoing   "Major MID" 
label variable minor_ongoing   "Minor MID" 


label variable divided   "Divided Government" 
label variable approval_q1 "Qtr. 1 Approval"
label variable election  "Election Year"
label variable oversight_change "Oversight Change"
label variable democracy "Joint Democracy"
label variable cinc_proportion "CINC Ratio"
label variable clean_russ_inf "Active Russian Operation"
label variable orourke_peace_years "Peace Years"
label variable orourke_peace_years_2 "Peace Years Squared"
label variable orourke_peace_years_3 "Peace Years Cubed"

* US Covert Onset Peace Years
label variable us_peace_years "Peace Years"
label variable us_peace_years_2 "Peace Years Squared"
label variable us_peace_years_3 "Peace Years Cubed"


mvencode orourke_peace_years orourke_peace_years_2  orourke_peace_years_3 us_peace_years us_peace_years_2 us_peace_years_3 minor_us_py major_us_py, mv(0)

* Adds peace years squared and cubed 
generate minor_us_py_2 = minor_us_py^2
generate minor_us_py_3 = minor_us_py^3
generate major_us_py_2 = major_us_py ^2
generate major_us_py_3 = major_us_py ^3


*  Peace Year Labels
label variable minor_us_py "Peace Years"
label variable minor_us_py_2 "Peace Years Squared"
label variable minor_us_py_3 "Peace Years Cubed"
label variable major_us_py "Peace Years"
label variable major_us_py_2 "Peace Years Squared"
label variable major_us_py_3 "Peace Years Cubed"


*\ First bivariate probit model: orourke ongoing and major gml ongoing 


biprobit (orourke_covert_intervention = i.divided i.election approval_q1 i.democracy cinc_proportion i.clean_russ_inf i.oversight_change orourke_peace_years orourke_peace_years_2 orourke_peace_years_3) ///
         (major_ongoing = i.divided i.election approval_q1 i.democracy cinc_proportion i.clean_russ_inf i.oversight_change major_us_py major_us_py_2 major_us_py_3),vce(robust)
                       
                       
                       
                     
est sto bp1 
esttab bp1, se label nobaselevels starlevels(* 0.05) unstack title("Bivariate Probit Model of Ongoing O'Rourke Covert Operations and Major MIDs") booktabs


 * Predicted marginal probabilities of y1=1 and y2=1
 predict biprob_or1, pmarg1 
 predict biprob_or2, pmarg2 

* Predicted joint probabilities of y1=0 and y2=0, y1=0 and y2=1, y1=1 and y2=0, and y1=1 and y2=1
predict biprob_or_00, p00 
predict biprob_or_01, p01 
predict biprob_or_10, p10 
predict biprob_or_11, p11 

*\ Summarizing predicted values
summarize orourke_onset major_us_onset biprob_or1 biprob_or2 
summarize biprob_or_00 biprob_or_01 biprob_or_10 biprob_or_11

* Marginal effects 
margins, dydx(*) atmeans predict(p00)
margins, dydx(*) atmeans predict(p01)
margins, dydx(*) atmeans predict(p10)
margins, dydx(*) atmeans predict(p11)

*\ Second bivariate probit model: orourke and minor onset  


biprobit (orourke_covert_intervention = i.divided i.election approval_q1 i.democracy cinc_proportion i.clean_russ_inf i.oversight_change orourke_peace_years orourke_peace_years_2 orourke_peace_years_3) ///
 (minor_ongoing = i.divided i.election approval_q1 i.democracy cinc_proportion i.clean_russ_inf i.oversight_change minor_us_py minor_us_py_2 minor_us_py_3) , vce(robust)

est sto bp2 
esttab bp2, se label nobaselevels starlevels(* 0.05) unstack title("Bivariate Probit Model of Ongoing O'Rourke Covert Operations and Minor MIDs") booktabs


 * Predicted marginal probabilities of y1=1 and y2=1
 predict biprob_ormin_1, pmarg1 
 predict biprob_ormin_2, pmarg2 

* Predicted joint probabilities of y1=0 and y2=0, y1=0 and y2=1, y1=1 and y2=0, and y1=1 and y2=1
predict biprob_ormin_00, p00 
predict biprob_ormin_01, p01 
predict biprob_ormin_10, p10 
predict biprob_ormin_11, p11 

*\ Summarizing predicted values
summarize orourke_onset minor_us_onset biprob_ormin_1 biprob_ormin_2 
summarize biprob_ormin_00 biprob_ormin_01 biprob_ormin_10 biprob_ormin_11

* Marginal effects 
margins, dydx(*) atmeans predict(p00)
margins, dydx(*) atmeans predict(p01)
margins, dydx(*) atmeans predict(p10)
margins, dydx(*) atmeans predict(p11)



*\ Third bivariate probit model: pooled covert onset and major onset 
biprobit (us_covert_operation = i.divided i.election approval_q1 i.democracy cinc_proportion i.clean_russ_inf i.oversight_change us_peace_years us_peace_years_2 us_peace_years_3) ///
 (major_ongoing = i.divided i.election approval_q1 i.democracy cinc_proportion i.clean_russ_inf i.oversight_change major_us_py major_us_py_2 major_us_py_3) , vce(robust)

est sto bp3 

esttab bp3, se label nobaselevels starlevels(* 0.05) unstack title("Bivariate Probit Model of Ongoing Pooled Covert Operations and Major MIDs") booktabs


 * Predicted marginal probabilities of y1=1 and y2=1
 predict biprob_pmaj_1, pmarg1 
 predict biprob_pmaj_2, pmarg2 

* Predicted joint probabilities of y1=0 and y2=0, y1=0 and y2=1, y1=1 and y2=0, and y1=1 and y2=1
predict biprob_pmaj_00, p00 
predict biprob_pmaj_01, p01 
predict biprob_pmaj_10, p10 
predict biprob_pmaj_11, p11 

*\ Summarizing predicted values
summarize us_covert_onset major_us_onset biprob_pmaj_1 biprob_pmaj_2 
summarize biprob_pmaj_00 biprob_pmaj_01 biprob_pmaj_10 biprob_pmaj_11

* Marginal effects 
margins, dydx(*) atmeans predict(p00)
margins, dydx(*) atmeans predict(p01)
margins, dydx(*) atmeans predict(p10)
margins, dydx(*) atmeans predict(p11)


*\ Fourth bivariate probit model: pooled covert onset and minor onset 
biprobit (us_covert_operation = i.divided i.election approval_q1 i.democracy cinc_proportion i.clean_russ_inf i.oversight_change us_peace_years us_peace_years_2 us_peace_years_3) ///
 (minor_ongoing = i.divided i.election approval_q1 i.democracy cinc_proportion i.clean_russ_inf i.oversight_change minor_us_py minor_us_py_2 minor_us_py_3) , vce(robust) 

est sto bp4 

esttab bp4, se label nobaselevels starlevels(* 0.05) unstack title("Bivariate Probit Model of Pooled Covert Operations and Minor MIDs") booktabs


 * Predicted marginal probabilities of y1=1 and y2=1
 predict biprob_pmin_1, pmarg1 
 predict biprob_pmin_2, pmarg2 

* Predicted joint probabilities of y1=0 and y2=0, y1=0 and y2=1, y1=1 and y2=0, and y1=1 and y2=1
predict biprob_pmin_00, p00 
predict biprob_pmin_01, p01 
predict biprob_pmin_10, p10 
predict biprob_pmin_11, p11 

*\ Summarizing predicted values
summarize us_covert_onset minor_us_onset biprob_pmin_1 biprob_pmin_2 
summarize biprob_pmin_00 biprob_pmin_01 biprob_pmin_10 biprob_pmin_11

* Marginal effects 
margins, dydx(*) atmeans predict(p00)
margins, dydx(*) atmeans predict(p01)
margins, dydx(*) atmeans predict(p10)
margins, dydx(*) atmeans predict(p11)
                      
